﻿@page
@model FytSoa.Web.Pages.FytAdmin.Sys.AdminModifyModel
@{
    ViewData["Title"] = "编辑/添加用户";
    Layout = "~/Pages/FytAdmin/_Layout.cshtml";
}
<style>
    .organize-tree {
        position: absolute;
        background-color: #fff;
        padding: 5px 25px;
        z-index: 1000;
        box-shadow: 0 0 24px rgba(0,0,0,.18);
        opacity: 0;
        height: 0;
        display: none;
    }

        .organize-tree.active {
            display: block;
            opacity: 1;
            height: auto;
            max-height: 500px;
            overflow: auto;
            transition: all .5s;
        }

        .organize-tree .ztree li a {
            height: 22px !important;
        }
</style>
<form class="layui-form form-cus" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-block">
            <input type="text" name="DepartmentName" id="DepartmentName" value="@Model.adminModel.DepartmentName" lay-verify="required" lay-verType="tips" autocomplete="off" placeholder="请选择所属部门" class="layui-input">
            <div class="organize-tree">
                <ul id="tree" class="ztree layui-tree-cus"></ul>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">登录账号</label>
            <div class="layui-input-inline">
                <input type="text" name="LoginName" value="@Model.adminModel.LoginName" maxlength="20" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">登录密码</label>
            <div class="layui-input-inline">
                <input type="password" name="LoginPwd" value="@Model.adminModel.LoginPwd" maxlength="20" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="TrueName" value="@Model.adminModel.TrueName" maxlength="10" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">编号</label>
            <div class="layui-input-inline">
                <input type="text" name="Number" value="@Model.adminModel.Number" maxlength="6" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-inline">
                <input type="radio" name="Sex" value="男" title="男" @(Model.adminModel.Sex == "男" ? "checked" : "")>
                <input type="radio" name="Sex" value="女" title="女" @(Model.adminModel.Sex == "女" ? "checked" : "")>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <input type="checkbox" @(Model.adminModel.Status ? "checked" : "") name="Status" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">手机号码</label>
            <div class="layui-input-inline">
                <input type="text" name="Mobile" value="@Model.adminModel.Mobile" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="email" name="Email" value="@Model.adminModel.Email" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
            <button type="button" class="layui-btn layui-btn-primary btn-open-close">取消</button>
        </div>
    </div>    
    <input type="hidden" name="Guid" id="Guid" value="@Model.adminModel.Guid" />
    <input type="hidden" name="DepartmentGuid" id="DepartmentGuid" value="@Model.adminModel.DepartmentGuid" />
</form>
<link rel="stylesheet" href="~/themes/ztree/css/metroStyle/metroStyle.css" type="text/css">
@section Scripts{
    <script>
        layui.config({
            base: '/themes/js/modules/'
        }).use(['layer', 'jquery', 'common', 'form','ztree'], function () {
            var form = layui.form, $ = layui.$, os = layui.common;
            var index = parent.layer.getFrameIndex(window.name);
            //监听提交
            form.on('submit(submit)', function (data) {
                var urls = "api/admin/add";
                if ($("#Guid").val()) {
                    urls = "api/admin/edit";
                }                
                data.field.Status = data.field.Status === 'on' ? true : false;
                os.ajax(urls, data.field, function (res) {
                    if (res.statusCode == 200) {
                        parent.layer.close(index);
                    }
                    else {
                        os.error(res.message);
                    }
                });
                return false;
            });
            $(".btn-open-close").on('click', function () {
                parent.layer.close(index);
            });

            var setting = {
                async: {
                    enable: true,
                    url: "/api/organize/gettree"
                },
                callback: {
                    onClick: onClick
                }
            };
            $("#DepartmentName").click(function () {
                $(".organize-tree").addClass('active');
            });
            $(".organize-tree").mouseleave(function () {
                $(".organize-tree").removeClass('active');
            });
            $.fn.zTree.init($("#tree"), setting);
            function onClick(event, treeId, treeNode, clickFlag) {
                $("#DepartmentGuid").val(treeNode.guid);
                $("#DepartmentName").val(treeNode.name);
                $(".organize-tree").removeClass('active');
            }
        });
    </script>
}

